//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;


int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	int n, m, i, j;
	char s[100][101], ok, c;
	
	scanf("%d%d", &n, &m);
	
	for(i=0;i<n;++i){
		scanf("%s", s[i]);
	}
	
	ok=1;
	for(i=0;i<n&&ok;++i){
		c=s[i][0];
		for(j=1;j<m&&ok;++j){
			if(s[i][j]!=c)ok=0;
		}
	}
	for(i=1;i<n-1&&ok;++i){
		if( (s[i-1][0]==s[i][0]) || (s[i+1][0]==s[i][0]) )ok=0;
	}
	
	
	if(ok)printf("YES");
	else  printf("NO");
	
	return 0;
}
